<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function round(){
            var count = 0;
            var value = document.getElementById("txt").value;
            //查询文本中的指定字符的数量并过滤。
            while (value.indexOf("js") != -1){
                count++;
                value = value.replace(/js/,"*");
            }
            document.getElementById("txt").value = value;
            alert("共替换了"+count);
        }
    </script>
</head>
<body>
<input type="text" id="txt">
<input type="button" value="ok" onclick="round()">

</body>
</html>